﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Lable"%>
<%@page import="com.zaofan.cache.CacheManage"%>
<%@page import="com.zaofan.constant.LableConstant"%>
<%@page import="com.zaofan.bean.Admin"%>
<%@page import="com.zaofan.bean.AdminType"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
Admin admin = (Admin)session.getAttribute("admin");
if(admin == null){
	response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
	return;
	}
if(admin.getType() != AdminType.admin.ordinal() &&  admin.getType() != 4){
	response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
	return;
}
	String shopId = request.getParameter("shopId");
	if(shopId == null){
		out.print("非法访问!!");
		return;
	}
	String id = request.getParameter("id");
	String action = "add";
	if(id == null){
		id="";
		action = "add";
	}else{
		action = "update";
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品增加</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/bootstrap-timepicker.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/chosen.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/css/uploadify.css" />
	<script src="<%=contextPath%>/admin/ckeditor/ckeditor.js"
	type="text/javascript"></script>

<script type="text/javascript">
       var contextPath='<%=contextPath%>';
       var shopId='<%=shopId%>';
       var id='<%=id%>';
       var action='<%=action%>';
       var attrJson = '<%=CacheManage.attr_json%>';
</script>
</head>
<body style="background-color: #fff;">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try {
				ace.settings.check('breadcrumbs', 'fixed')
			} catch (e) {
			}
		</script>
		<ul class="breadcrumb">
			<li><i class="icon-home home-icon"></i> <a
				href="<%=contextPath%>/admin/admin/index.jsp">首页</a></li>
			<li class="active">管理</li>
		</ul>
	</div>
	<div class="page-content">
		<div class="page-header">
			<h1>
				管理 <small> <i class="icon-double-angle-right"> 产品添加 </i>
				</small>
			</h1>
		</div>
		<!-- /.page-header -->
		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<a href="javascript:history.go(-1);" class="btn btn-primary" role="button">返回</a>
				<div class="alert alert-info" role="alert">产品管理</div>
				<div class="popover-inner" style="">
					<div class="popover-content" id="" style="">
						<form class="form-horizontal" style="padding-top: 10px;"
							method="post" id="productForm">
							<input type="hidden" value="<%=id %>" name="id" />
							<input type="hidden" value="<%=shopId %>" name="shopId" ></input>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">产品名称：</label>
								<div class="col-sm-9">
									<input name="name" id="name" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group " >
								<label for="" class="col-sm-2 control-label">产品价格：</label>
								<div class="col-sm-9">
									<input name="price" id="price" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<%-- TODO 酒店注释--%>
							<%--<div class="form-group " >--%>
								<%--<label for="" class="col-sm-2 control-label">酒店价格：</label>--%>
								<%--<div class="col-sm-9">--%>
									<%--<input name="hotelPrice" id="hotelPrice" class="form-control" value="" />--%>
								<%--</div>--%>
								<%--<span class="input_tip" style="line-height: 30px;">*</span>--%>
							<%--</div>--%>



							<%--<div class="form-group " >--%>
								<%--<label for="" class="col-sm-2 control-label">产品进价（供货价）：</label>--%>
								<%--<div class="col-sm-9">--%>
									<%--<input name=purchasePrice id="purchasePrice" class="form-control" value="" />--%>
								<%--</div>--%>
								<%--<span class="input_tip" style="line-height: 30px;">*</span>--%>
							<%--</div>--%>
							<div class="form-group " >
								<label for="" class="col-sm-2 control-label">产品数量：</label>
								<div class="col-sm-9">
									<input name="count" id="count" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品描述：</label>
								<div class="col-sm-9 bootstrap-timepicker">
									<input id="des" name="des" type="text" class="form-control" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品明细：</label>
								<div class="col-sm-9 bootstrap-timepicker">
									<input id="productItems" name="productItems" type="text" class="form-control" 
									placeholder='请按“鲜肉包*1 + 原味豆浆*1”的格式填写'/>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品类别：</label>
								<div class="col-sm-9">
									<select name="categoryId" id="categoryId">
									</select>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">早餐类别：</label>
								<div class="col-sm-9">
									<select name="productClassId" id="typeid" onchange="typechange()">
									</select>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
                            <script>
                                function typechange() {
                                    var typeid = $("#typeid").find("option:selected").text();
                                    if (typeid == '逼格' 
                                    		|| typeid == '逼格类'
                                    		|| typeid == '进口'
                                    		|| typeid == '进口类'){
                                        $("#sdesdiv").show();
                                    }else {
                                        $("#sdesdiv").hide();
                                    }
                                }
                            </script>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">是否精品：</label>
								<div class="col-sm-9">
									<select name="isQuality" id="isQuality" onchange="isQualityChange()">
                                        <option value="0" >否</option>
                                        <option value="1" >是</option>
									</select>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<script>
                                function isQualityChange() {
                                    var typeid = $("#isQuality").val();
                                    if (typeid == 1){
                                        $("#qualityExtend").show();
                                    }else {
                                        $("#qualityExtend").hide();
                                    }
                                }
                            </script>
                            <div class="form-group" style="display:none" id="qualityExtend">
			                    <div class="form-group">
									<label for="" class="col-sm-2 control-label">配送日期(yyyy-MM-dd)：</label>
										<input type="text" name="sendDate" id="sendDate" />
									<span class="input_tip" style="line-height: 30px;">*</span>
								</div>
                            	<div class="form-group" >
									<input type="hidden" value="" name="qualityimage" id="qualityproductImage" />
									<label for="" class="col-sm-2 control-label">产品图片：</label>
									<div class="col-sm-9">
										<div id="qualityimageProduct" style="display:none;">
											<img src="" width="50" height="50" />
										</div>
										<br/>
										<input type="file" id="qualityimage" />
									</div>
									<span class="input_tip" style="line-height: 30px;">*</span>
								</div>
								<div class="form-group" >
									<input type="hidden" value="" name="qualitybigImage" id="qualityproductBigImage" />
									<label for="" class="col-sm-2 control-label">产品详情页图片：</label>
									<div class="col-sm-9">
										<div id="qualitybigImageProduct" style="display:none;">
											<img src="" width="50" height="50" />
										</div>
										<br/>
										<input type="file" id="qualitybigImage" />
									</div>
									<span class="input_tip" style="line-height: 30px;">*</span>
								</div>
								<div class="form-group" >
									<input type="hidden" value="" name="qualitytimeOutImage" id="qualityproductTimeOutImage" />
									<label for="" class="col-sm-2 control-label">过期图片：</label>
									<div class="col-sm-9">
										<div id="qualitytimeOutImageProduct" style="display:none;">
											<img src="" width="50" height="50" />
										</div>
										<br/>
										<input type="file" id="qualitytimeOutImage" />
									</div>
									<span class="input_tip" style="line-height: 30px;">*</span>
								</div>
                            </div>
							<div class="form-group" style="display:none" id="productIdsBox" >
								<label for="" class="col-sm-2 control-label">产品id：</label>
								<div class="col-sm-9">
									<input name="productIds" id="productIds" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">以|分割</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品属性：</label>
								<div class="col-sm-9">
									<input id="attrvalue" name="attr" type="hidden" />	
									<input id="attr"  type="text" readOnly="readOnly" class="form-control" />	
								</div>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">排序：</label>
								<div class="col-sm-9">
									<input name="sort" id="sort" class="form-control" value="0" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">显示类型：</label>
								<div class="col-sm-9">
									<input type="radio" value="page" name="showType" checked="checked" /> 页面显示
									<input type="radio" value="url" name="showType" /> 链接显示
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<input type="hidden" value="" name="image" id="productImage" />
								<label for="" class="col-sm-2 control-label">产品图片：</label>
								<div class="col-sm-9">
									<div id="imageProduct" style="display:none;">
										<img src="" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="image" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>





<%--// TODO 酒店注释--%>
							<%--<div class="form-group" >--%>
								<%--<input type="hidden" value="" name="hotelImage" id="hotelImage" />--%>
								<%--<label for="" class="col-sm-2 control-label">酒店图片：</label>--%>
								<%--<div class="col-sm-9">--%>
									<%--<div id="imageHotel" style="display:none;">--%>
										<%--<img src="" width="50" height="50" />--%>
									<%--</div>--%>
									<%--<br/>--%>
									<%--<input type="file" id="imagesHotel" />--%>
								<%--</div>--%>
								<%--<span class="input_tip" style="line-height: 30px;">*</span>--%>
							<%--</div>--%>

							<div class="form-group" >
								<input type="hidden" value="" name="bigImage" id="productBigImage" />
								<label for="" class="col-sm-2 control-label">产品详情页图片：</label>
								<div class="col-sm-9">
									<div id="bigImageProduct" style="display:none;">
										<img src="" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="bigImage" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<input type="hidden" value="" name="horImage" id="productHorImage" />
								<label for="" class="col-sm-2 control-label">水平图片：</label>
								<div class="col-sm-9">
									<div id="horImageProduct" style="display:none;">
										<img src="" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="horImage" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" id="tip">
								<label for="" class="col-sm-2 control-label"></label>
								<div class="col-sm-9">
								</div>
							</div>
							<div class="form-group" hidden id="sdesdiv">
								<label for="" class="col-sm-2 control-label">特殊品类描述：</label>
								<div class="col-sm-9 bootstrap-timepicker">
									<input id="sdes" name="sdes" type="text" class="form-control" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<script>
								CKEDITOR.replace('sdes', {
									filebrowserImageBrowseUrl : 'servlet/ImageBrower.brower',
									filebrowserImageUploadUrl :'servlet/ImageUpload.upload'
								});
							</script>
						</form>
					</div>
					<div class="popover-footer"
						style="overflow: hidden; text-align: center;">
						<button type="button" class="btn btn-primary"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel">
							<i class="icon-ok"></i>取消
						</button>
						<button type="button" class="btn btn-danger"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="save">
							<i class="icon-edit"></i>保存
						</button>

					</div>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</div>
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>
	
	<div id="cityEditBox"
		style="display: none; z-index: 99; width: 600px; position: fixed; left: 36%; top: 20%; border: 1px solid #ccc; border-radius: 4px !important;">
		<div class="arrow"></div>
		<div class="popover-inner" style="">
			<h3 class="popover-title" id="">产品属性设置</h3>
			<div class="popover-content" id="" style="background-color: #F5F5F5;">
				<a href="javascript:void(0)" id="addAttrItem">增加</a>
				<table id="sample-table-2"
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th style="text-align: center;">属性</th>
								<th style="text-align: center;">属性值</th>
								<th style="text-align: center;">产品数量</th>
								<th style="text-align: center;">产品价格</th>
								<th style="text-align: center;">操作</th>
							</tr>
						</thead>
						<tbody id="data-list"  style="text-align: center;">
							
						</tbody>
				</table>
			</div>
			<div class="popover-footer"
				style="background-color: #F5F5F5; overflow: hidden; text-align: center;">
				<button type="button" class="btn btn-primary"
					style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel1">
					<i class="icon-ok"></i>取消
				</button>
				<button type="button" class="btn btn-danger"
					style="padding: 0px; margin: 0px 5px 5px 0px;" id="save1">
					<i class="icon-edit"></i>保存
				</button>

			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>

	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script
		src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-timepicker.min.js"></script>
	<script src="<%=contextPath%>/admin/js/jquery.uploadify.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>

	<script type="text/javascript">
		var options = "";
		var old = "";
		init();
		function init(){
			var json = eval(attrJson);
			options = '<tr><td><select class="attrIds" ><option value="-1" >请选择属性值</option>';
			for(var i = 0 ; i < json.length ; i++){
				options += '<option value="'+json[i].id+'">' + json[i].attrName + '</optopn>';
			}
			options += '</select></td>';
			options += '<td><input type="text" value="" class="attrValues" style="width:50px" /></td>';
			options += '<td><input type="text" value="" class="counts" style="width:50px" /></td>';
			options += '<td><input type="text" value="" class="prices" style="width:50px" /></td>';
			options += '<td><a href="javascript:void(0)" class="delAttr">删除</a></td>';
			options += '</tr>';
			$("#loading").show();
			$.ajax({
				url : contextPath + '/category',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'shop_category',
					shopId:shopId
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						var options = "<option value='-1'>请选择产品类别</option>";
						var data = rs.data;
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value="'+data[i].id+'" data="'+data[i].type+'">'+ data[i].name + '</option>';
						}
						$("#categoryId").append(options);
						$("#categoryId").change(function(){
							var type = $(this).find("option:checked").attr("data");
							if(type == 1){
								$("#productIdsBox").show();
							}else{
								$("#productIdsBox").hide();
							}
						});
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			$.ajax({
				url : contextPath + '/category',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'productType',
					shopId:shopId
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						var options = "<option value='-1'>请选择早餐类别</option>";
						var data = rs.data;
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value="'+data[i].id+'">'+ data[i].className + '</option>';
						}
						$("#typeid").append(options);
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			
		}
		
	
		$("#save").bind("click", function() {
			if ($("#name").val() == "") {
				showMessage("请输入产品名称!!!");
				return;
			}
			if ($("#price").val() == "") {
				showMessage("请输入产品价格!!!");
				return;
			}
			// TODO 酒店注释
//			if ($("#hotelPrice").val() == "") {
//				showMessage("请输入酒店价格!!!");
//				return;
//			}
			// TODO 酒店注释
//			if (isNaN($("#hotelPrice").val() )) {
//				showMessage("价格必须为数字！");
//				return;
//			}

//			if ($("#purchasePrice").val() == "") {
//				showMessage("请输入产品进价（供货价）!!!");
//				return;
//			}
			if (isNaN($("#price").val() )) {
				showMessage("产品价格必须为数字!!!");
				return;
			}
//			if (isNaN($("#purchasePrice").val() )) {
//				showMessage("产品进价必须为数字!!!");
//				return;
//			}
			if ($("#count").val() == "") {
				showMessage("请输入产品每日限额!!!");
				return;
			}
			if (isNaN($("#count").val() )) {
				showMessage("产品每日限额必须为数字!!!");
				return;
			}
			if ($("#des").val() == "") {
				showMessage("请输入产品描述!!!");
				return;
			}
			if ($("#productItems").val() == "") {
				showMessage("请输入产品明细，如：豆沙包*1 + 豆浆*1");
				return;
			}
			if ($("#categoryId").val() == -1){
				showMessage("请选择产品类别!!!");
				return;
			}
			if (isNaN($("#sort").val() )) {
				showMessage("产品排序必须为数字!!!");
				return;
			}
			var type = $("#categoryId").find("option:checked").attr("data");
			//if(type == 1){
				//if($("#productIds").val() == ""){
					//showMessage("请填写套餐的产品id");
					//return;
				//}
			//}
            var sdate = CKEDITOR.instances.sdes.getData();


            $("#sdes").val(sdate);

			$("#loading").show();
			$("#productForm").ajaxSubmit({
				type : "POST",
				url : contextPath + '/product?action='+action,
				dataType : 'json',
				success : function(data) {
					if (data.success) {
						showMessage(data.msg);
						setTimeout(function() {
							window.location.href = "shopProductList.jsp?shopId="+shopId;
						}, 2000);
					} else {
						showMessage(data.msg);
					}
					$("#loading").hide();
				},
				error : function(msg) {
					$("#loading").hide();
					showMessage("操作失败");
				}
			});
		});
		$("#address").focus(function(){
			var val = $("#cityId").val();
			if(val == 0){
				showMessage("请选择商品城市信息");
				$(this).blur();
				return;
			}
		});
		
		$("#image").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#productImage").val(imgsrc);
					$("#imageProduct").show();
					$("#imageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		$("#bigImage").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#productBigImage").val(imgsrc);
					$("#bigImageProduct").show();
					$("#bigImageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		// TODO 酒店注释
		<%--$("#imagesHotel").uploadify({--%>
			<%--'auto'           : true,--%>
			<%--'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',--%>
			<%--'uploader'       : '<%=contextPath%>/upload?action=image',--%>
			<%--'queueID'        : 'tip',//与下面的id对应--%>
			<%--'queueSizeLimit' :12,--%>
			<%--'fileTypeDesc'   : '图片文件',--%>
			<%--'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc--%>
			<%--'multi'          : true,--%>
			<%--'buttonText'     : '上传' ,--%>
			<%--onUploadSuccess : function(file, data,--%>
									   <%--response) {--%>
				<%--if (response) {--%>
					<%--var json = eval("(" + data+ ")");--%>
					<%--var imgsrc = json.data;--%>
					<%--$("#hotelImage").val(imgsrc);--%>
					<%--$("#imageHotel").show();--%>
					<%--$("#imageHotel").find("img").attr("src",contextPath + imgsrc);--%>
				<%--}--%>
			<%--}--%>
		<%--});--%>

		$("#horImage").uploadify({
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#productHorImage").val(imgsrc);
					$("#horImageProduct").show();
					$("#horImageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		
		$("#qualityimage").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#qualityproductImage").val(imgsrc);
					$("#qualityimageProduct").show();
					$("#qualityimageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		$("#qualitybigImage").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#qualityproductBigImage").val(imgsrc);
					$("#qualitybigImageProduct").show();
					$("#qualitybigImageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		
		$("#qualitytimeOutImage").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#qualityproductTimeOutImage").val(imgsrc);
					$("#qualitytimeOutImageProduct").show();
					$("#qualitytimeOutImageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		
		$("#attr").click(function(){
			$("#cityEditBox").show();
			if($("#attr").val() == ""){
				$("#data-list").append(options);
			}else{
			}
			$(".delAttr").unbind("click");
			$(".delAttr").click(function(){
				$(this).parent().parent().remove();
			});			
		});
		
		$("#cancel1").click(function(){
			if($("#attr").val() == ""){
				 $("#data-list").empty();
			}
			$("#cityEditBox").hide();
		});
		
		$("#save1").click(function(){
			var values = "";
			var value = "";
			var attrs = $(".attrIds");
			for(var i = 0 ; i < attrs.length ; i++){
				var item = $(attrs[i]);
				if(item.val() == -1){
					showMessage("请填写正确的信息");
					return;
				}
				values += "" + item.val() + ",";
				value += "" + item.find("option:selected").text() + ",";
				var name = item.parent().parent().find(".attrValues").val();
				var count = item.parent().parent().find(".counts").val();
				var price = item.parent().parent().find(".prices").val();
				if(name == ""){
					showMessage("请填写正确的信息");
					return;
				}
				if(count == ""){
					showMessage("请填写正确的信息");
					return;
				}
				if (isNaN(count)){
					showMessage("数量必须为数字!!!");
					return;
				}
				if(price == ""){
					showMessage("请填写正确的信息");
					return;
				}
				if (isNaN(price)) {
					showMessage("价格必须为数字!!!");
					return;
				}
				values += name +','+ count + "," + price + "-";
				value += name +',数量:'+ count + ",价格:" + price + "元-";
			}
			if(values != ""){
				values = values.substring(0,values.length - 1);
				$("#attr").val(value);
				$("#attrvalue").val(values);
			}
			old = $("#data-list").html();
			$("#cityEditBox").hide();
		});
		
		
		
		$("#addAttrItem").click(function(){
			$("#data-list").append(options);
			$(".delAttr").unbind("click");
			$(".delAttr").click(function(){
				$(this).parent().parent().remove();
			});	
		});
		
		
		$(function(){
			if(action == "update"){
				$.ajax({
					url : contextPath + '/product',
					type : "POST",
					dataType : 'json',
					data : {
						action : 'get',
						id:id
					},
					success : function(rs, textStatus, jqXHR) {
						$("#loading").hide();
						if (rs.success) {
							var data = rs.data;
							$("#name").val(data.name);
							$("#price").val(data.price);

//							$("#purchasePrice").val(data.purchasePrice);
							// TODO 酒店注释
//                            $("#hotelPrice").val(data.hotelPrice)
							$("#count").val(data.count);
							$("#des").val(data.des);
							$("#productItems").val(data.productItems);
							$("#categoryId").val(data.categoryId);
							$("#isQuality").val(data.isQuality);
							$("#sendDate").val(data.sendDate);
							$("#typeid").val(data.productClassId);
							$("#sort").val(data.sort);
                            if (data.productClassId == 6){
                                $("#sdesdiv").show();
                            }
                            
                                var typeid1 = $("#typeid").find("option:selected").text();
                                if (typeid1 == '逼格' 
                                		|| typeid1 == '逼格类'
                                		|| typeid1 == '进口'
                                		|| typeid1 == '进口类'){
                                    $("#sdesdiv").show();
                                }else {
                                    $("#sdesdiv").hide();
                                }
                         
   
                            
                                var isQuality1 = $("#isQuality").val();
                                if (isQuality1 == 1){
                                    $("#qualityExtend").show();
                                }else {
                                    $("#qualityExtend").hide();
                                }

                      
							$("#sdes").val(data.sdes);
                            console.log(data.sdes);
                            CKEDITOR.instances.sdes.setData(data.sdes);

							$("input[name='showType'][value='"+data.showType+"']").prop("checked","checked");
							$("#productImage").val(data.image);
							$("#imageProduct").show();
							$("#imageProduct").find("img").attr("src",contextPath + data.image);
							
							$("#productBigImage").val(data.bigImage);
							$("#bigImageProduct").show();
							$("#bigImageProduct").find("img").attr("src",contextPath + data.bigImage);
							
							$("#productTimeOutImage").val(data.timeOutImage);
							$("#timeOutImageProduct").show();
							$("#timeOutImageProduct").find("img").attr("src",contextPath + data.timeOutImage);

//							// TODO 酒店注释
//							$("#hotelImage").val(data.imageHotel);
//							$("#imageHotel").show();
//							$("#imageHotel").find("img").attr("src",contextPath + data.imageHotel);
							
							$("#qualityproductImage").val(data.qualityimage);
							$("#qualityimageProduct").show();
							$("#qualityimageProduct").find("img").attr("src",contextPath + data.qualityimage);
							
							$("#qualityproductBigImage").val(data.qualitybigImage);
							$("#qualitybigImageProduct").show();
							$("#qualitybigImageProduct").find("img").attr("src",contextPath + data.qualitybigImage);
							
							$("#qualityproductTimeOutImage").val(data.qualitytimeOutImage);
							$("#qualitytimeOutImageProduct").show();
							$("#qualitytimeOutImageProduct").find("img").attr("src",contextPath + data.qualitytimeOutImage);
							if(data.attrs != null){
								var option = "";
								var options = "";
								var values= "";
								var json = eval(attrJson);
								for(var i = 0 ; i < data.attrs.length;i++){
									var item = data.attrs[i];
									option += item.attrName + ',' + item.attrValue + ',数量:' + item.count + ',价格:' + item.price + "元" + '-';
									values += item.Id + "," +  item.attrValue +','+ item.count + "," + item.price + "-";
									options += '<tr><td><select class="attrIds" ><option value="-1" >请选择属性值</option>';
									for(var j = 0 ; j < json.length ; j++){
										if(item.attrId == json[j].id){
											options += '<option value="'+json[j].id+'" selected="selected">' + json[j].attrName + '</optopn>';
										}else{
											options += '<option value="'+json[j].id+'">' + json[j].attrName + '</optopn>';
										}
									}
									options += '</select></td>';
									options += '<td><input type="text" value="'+item.attrValue+'" class="attrValues" style="width:50px" /></td>';
									options += '<td><input type="text" value="'+item.count+'" class="counts" style="width:50px" /></td>';
									options += '<td><input type="text" value="'+item.price+'" class="prices" style="width:50px" /></td>';
									options += '<td><a href="javascript:void(0)" class="delAttr">删除</a></td>';
									options += '</tr>';
								}
								$("#attr").val(option);
								$("#attrvalue").val(values);
								old = options;
								$("#data-list").html(options);
								$(".delAttr").unbind("click");
								$(".delAttr").click(function(){
									$(this).parent().parent().remove();
								});	
							}
						} else{
							showMessage(rs.msg);
						}
						$("#loading").hide();
					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
				}); 
			}
		});
	</script>
</body>
</html>